package com.shop.czlmshop.controller;

import com.github.pagehelper.PageHelper;
import com.shop.czlmshop.pojo.Product;
import com.shop.czlmshop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @version: V1.0
 * @author: xmy
 * @className: ProductController
 * @description: 商品控制器
 * @data: 2019-04-29 13:12
 **/
@Controller
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * @version: V1.0
     * @author: xmy
     * @className: ProductController
     * @description: 查询人气销量商品
     * @data: 2019-05-05 10:36
     **/
    @GetMapping("/selProductList")
    @ResponseBody
    public List<Product> selProductOrderBySales(Integer queryType,Integer pageNum,Integer pageSize){
        List<Product> productList = null;
        if (pageNum==null){
            pageNum=1;
        }
        //如果queryType==1,查询人气销量的商品列表
        if (queryType==1){
            PageHelper.startPage(pageNum,pageSize);
            productList = productService.selProductOrderBySales();
        }else if (queryType==2){ //如果queryType==2,查询新品首发的商品列表
            productList = productService.selProductByTime();
        }else if (queryType==3){//如果queryType==3,查询今日折扣的商品列表
            productList = productService.selProductByDiscount();
        }
        return productList;
    }

    /**
     * @description: 查询平台推荐商品
     * @param:
     * @return:
     * @auther: XMY
     * @date: 2019-05-06 9:32
     */
    @GetMapping("/selRecommendProduct")
    @ResponseBody
    public List<Product> selRecommendProduct(){
        return productService.selRecommendProduct();
    }

    /**
     * @param categoryId
     * @description: 查询该分类下的商品列表
     * @param: categoryId 分类id
     * @return: List<Product>
     * @auther: XMY
     * @date: 2019-05-06 10:27
     */
    @GetMapping("/selCategoryList")
    @ResponseBody
    public List<Product> selCategoryList(Integer pageNum,Integer pageSize,Integer categoryId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> productList = productService.selCategoryList(categoryId);
        return productList;
    }
}
